{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Stage 1 Score Calculator\n",
    "Compute the SMAPE score for stage 1 prediction"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import gc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "submission_file = 'submit_1_model_8_ANN_with_Fibonacci_1_meas_absolute_error-prediction.csv'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "correct_file = 'submit_1_stage_1_correct.csv'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "%%% Reading submission submit_1_model_8_ANN_with_Fibonacci_1_meas_absolute_error-prediction.csv ... done!\n"
     ]
    }
   ],
   "source": [
    "print('%%% Reading submission', submission_file, '... ', end = '', flush = True)\n",
    "submit_df = pd.read_csv('../results/' + submission_file)\n",
    "print('done!')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "%%% Reading submission submit_1_stage_1_correct.csv ... done!\n"
     ]
    }
   ],
   "source": [
    "print('%%% Reading submission', correct_file, '... ', end = '', flush = True)\n",
    "correct_df = pd.read_csv('../results/' + correct_file)\n",
    "print('done!')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 8703780 entries, 0 to 8703779\n",
      "Data columns (total 2 columns):\n",
      "Id        object\n",
      "Visits    float64\n",
      "dtypes: float64(1), object(1)\n",
      "memory usage: 132.8+ MB\n"
     ]
    }
   ],
   "source": [
    "submit_df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 8703780 entries, 0 to 8703779\n",
      "Data columns (total 2 columns):\n",
      "Id        object\n",
      "Visits    float64\n",
      "dtypes: float64(1), object(1)\n",
      "memory usage: 132.8+ MB\n"
     ]
    }
   ],
   "source": [
    "correct_df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Id</th>\n",
       "      <th>Visits</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>bf4edcf969af</td>\n",
       "      <td>2.617</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>929ed2bf52b9</td>\n",
       "      <td>2.765</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ff29d0f51d5c</td>\n",
       "      <td>2.771</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>e98873359be6</td>\n",
       "      <td>2.914</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>fa012434263a</td>\n",
       "      <td>2.759</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>48f1e93517a2</td>\n",
       "      <td>2.846</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>5def418fcb36</td>\n",
       "      <td>2.697</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>77bd08134351</td>\n",
       "      <td>2.851</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>5889e6dbb16f</td>\n",
       "      <td>2.859</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>5f21fef1d764</td>\n",
       "      <td>2.815</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>6f07e1b8815a</td>\n",
       "      <td>2.817</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>228e54b5dea0</td>\n",
       "      <td>3.023</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>da1b34963ed7</td>\n",
       "      <td>2.794</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>ab5ccefaa2db</td>\n",
       "      <td>2.830</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>cbf42873ebf1</td>\n",
       "      <td>2.985</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>ac67e35ed44e</td>\n",
       "      <td>2.886</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>88c098aa640d</td>\n",
       "      <td>2.960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>7c72842a89d1</td>\n",
       "      <td>2.857</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>8ce002f2c329</td>\n",
       "      <td>2.994</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>5f72d9920560</td>\n",
       "      <td>2.945</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>f93afd7f5d9b</td>\n",
       "      <td>2.934</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>14011cb66f2d</td>\n",
       "      <td>2.932</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>0065551ac465</td>\n",
       "      <td>3.106</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>175f1872729e</td>\n",
       "      <td>2.849</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>31d756e83124</td>\n",
       "      <td>2.829</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>e186c2363c5e</td>\n",
       "      <td>3.124</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>3bce56c2b977</td>\n",
       "      <td>2.930</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>d497981dce77</td>\n",
       "      <td>2.802</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>c813cec10548</td>\n",
       "      <td>2.960</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>5123e0ed62c9</td>\n",
       "      <td>2.987</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703750</th>\n",
       "      <td>1fb8f902ad0f</td>\n",
       "      <td>263.568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703751</th>\n",
       "      <td>0107f6d7cd82</td>\n",
       "      <td>260.178</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703752</th>\n",
       "      <td>30c402ed9e49</td>\n",
       "      <td>249.322</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703753</th>\n",
       "      <td>935fa0168d01</td>\n",
       "      <td>251.775</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703754</th>\n",
       "      <td>1140b428380e</td>\n",
       "      <td>263.649</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703755</th>\n",
       "      <td>cc5eadae0d7a</td>\n",
       "      <td>281.058</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703756</th>\n",
       "      <td>f923701cdb05</td>\n",
       "      <td>255.189</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703757</th>\n",
       "      <td>905679a20d39</td>\n",
       "      <td>252.426</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703758</th>\n",
       "      <td>642354a50690</td>\n",
       "      <td>249.026</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703759</th>\n",
       "      <td>7376c63bd4c1</td>\n",
       "      <td>248.855</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703760</th>\n",
       "      <td>1f0566b71f7e</td>\n",
       "      <td>251.129</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703761</th>\n",
       "      <td>938774bbb675</td>\n",
       "      <td>265.064</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703762</th>\n",
       "      <td>53c046bac8cb</td>\n",
       "      <td>277.688</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703763</th>\n",
       "      <td>ead2377353d3</td>\n",
       "      <td>265.633</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703764</th>\n",
       "      <td>efa87c7d5160</td>\n",
       "      <td>250.479</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703765</th>\n",
       "      <td>f239d6ceb17b</td>\n",
       "      <td>243.138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703766</th>\n",
       "      <td>0fef0826b1bc</td>\n",
       "      <td>241.120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703767</th>\n",
       "      <td>478d3c34b0c1</td>\n",
       "      <td>236.067</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703768</th>\n",
       "      <td>6a1b6e3028fc</td>\n",
       "      <td>254.573</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703769</th>\n",
       "      <td>3b5fb022accd</td>\n",
       "      <td>277.006</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703770</th>\n",
       "      <td>a4456a9d271d</td>\n",
       "      <td>254.513</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703771</th>\n",
       "      <td>d43a25cf4ef2</td>\n",
       "      <td>243.461</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703772</th>\n",
       "      <td>8f47d2e020cd</td>\n",
       "      <td>234.150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703773</th>\n",
       "      <td>a78af728d84b</td>\n",
       "      <td>228.954</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703774</th>\n",
       "      <td>d1ba45c7ec08</td>\n",
       "      <td>228.993</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703775</th>\n",
       "      <td>f69747f5ee68</td>\n",
       "      <td>248.284</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703776</th>\n",
       "      <td>2489963dc503</td>\n",
       "      <td>274.640</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703777</th>\n",
       "      <td>b0624c909f4c</td>\n",
       "      <td>252.518</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703778</th>\n",
       "      <td>24a1dfb06c10</td>\n",
       "      <td>235.425</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703779</th>\n",
       "      <td>add681d54216</td>\n",
       "      <td>231.818</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8703780 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                   Id   Visits\n",
       "0        bf4edcf969af    2.617\n",
       "1        929ed2bf52b9    2.765\n",
       "2        ff29d0f51d5c    2.771\n",
       "3        e98873359be6    2.914\n",
       "4        fa012434263a    2.759\n",
       "5        48f1e93517a2    2.846\n",
       "6        5def418fcb36    2.697\n",
       "7        77bd08134351    2.851\n",
       "8        5889e6dbb16f    2.859\n",
       "9        5f21fef1d764    2.815\n",
       "10       6f07e1b8815a    2.817\n",
       "11       228e54b5dea0    3.023\n",
       "12       da1b34963ed7    2.794\n",
       "13       ab5ccefaa2db    2.830\n",
       "14       cbf42873ebf1    2.985\n",
       "15       ac67e35ed44e    2.886\n",
       "16       88c098aa640d    2.960\n",
       "17       7c72842a89d1    2.857\n",
       "18       8ce002f2c329    2.994\n",
       "19       5f72d9920560    2.945\n",
       "20       f93afd7f5d9b    2.934\n",
       "21       14011cb66f2d    2.932\n",
       "22       0065551ac465    3.106\n",
       "23       175f1872729e    2.849\n",
       "24       31d756e83124    2.829\n",
       "25       e186c2363c5e    3.124\n",
       "26       3bce56c2b977    2.930\n",
       "27       d497981dce77    2.802\n",
       "28       c813cec10548    2.960\n",
       "29       5123e0ed62c9    2.987\n",
       "...               ...      ...\n",
       "8703750  1fb8f902ad0f  263.568\n",
       "8703751  0107f6d7cd82  260.178\n",
       "8703752  30c402ed9e49  249.322\n",
       "8703753  935fa0168d01  251.775\n",
       "8703754  1140b428380e  263.649\n",
       "8703755  cc5eadae0d7a  281.058\n",
       "8703756  f923701cdb05  255.189\n",
       "8703757  905679a20d39  252.426\n",
       "8703758  642354a50690  249.026\n",
       "8703759  7376c63bd4c1  248.855\n",
       "8703760  1f0566b71f7e  251.129\n",
       "8703761  938774bbb675  265.064\n",
       "8703762  53c046bac8cb  277.688\n",
       "8703763  ead2377353d3  265.633\n",
       "8703764  efa87c7d5160  250.479\n",
       "8703765  f239d6ceb17b  243.138\n",
       "8703766  0fef0826b1bc  241.120\n",
       "8703767  478d3c34b0c1  236.067\n",
       "8703768  6a1b6e3028fc  254.573\n",
       "8703769  3b5fb022accd  277.006\n",
       "8703770  a4456a9d271d  254.513\n",
       "8703771  d43a25cf4ef2  243.461\n",
       "8703772  8f47d2e020cd  234.150\n",
       "8703773  a78af728d84b  228.954\n",
       "8703774  d1ba45c7ec08  228.993\n",
       "8703775  f69747f5ee68  248.284\n",
       "8703776  2489963dc503  274.640\n",
       "8703777  b0624c909f4c  252.518\n",
       "8703778  24a1dfb06c10  235.425\n",
       "8703779  add681d54216  231.818\n",
       "\n",
       "[8703780 rows x 2 columns]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "submit_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Id</th>\n",
       "      <th>Visits</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>bf4edcf969af</td>\n",
       "      <td>7.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>929ed2bf52b9</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>ff29d0f51d5c</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>e98873359be6</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>fa012434263a</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>48f1e93517a2</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>5def418fcb36</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>77bd08134351</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>5889e6dbb16f</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>5f21fef1d764</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>6f07e1b8815a</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>228e54b5dea0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>da1b34963ed7</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>ab5ccefaa2db</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>cbf42873ebf1</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>ac67e35ed44e</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>88c098aa640d</td>\n",
       "      <td>321959.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>7c72842a89d1</td>\n",
       "      <td>1160760.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>8ce002f2c329</td>\n",
       "      <td>1158477.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>5f72d9920560</td>\n",
       "      <td>1138250.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>f93afd7f5d9b</td>\n",
       "      <td>51572.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>14011cb66f2d</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>0065551ac465</td>\n",
       "      <td>15.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>175f1872729e</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>31d756e83124</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>e186c2363c5e</td>\n",
       "      <td>9.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>3bce56c2b977</td>\n",
       "      <td>7.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>d497981dce77</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>c813cec10548</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>5123e0ed62c9</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703750</th>\n",
       "      <td>1fb8f902ad0f</td>\n",
       "      <td>376.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703751</th>\n",
       "      <td>0107f6d7cd82</td>\n",
       "      <td>332.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703752</th>\n",
       "      <td>30c402ed9e49</td>\n",
       "      <td>303.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703753</th>\n",
       "      <td>935fa0168d01</td>\n",
       "      <td>321.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703754</th>\n",
       "      <td>1140b428380e</td>\n",
       "      <td>342.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703755</th>\n",
       "      <td>cc5eadae0d7a</td>\n",
       "      <td>349.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703756</th>\n",
       "      <td>f923701cdb05</td>\n",
       "      <td>296.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703757</th>\n",
       "      <td>905679a20d39</td>\n",
       "      <td>235.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703758</th>\n",
       "      <td>642354a50690</td>\n",
       "      <td>279.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703759</th>\n",
       "      <td>7376c63bd4c1</td>\n",
       "      <td>248.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703760</th>\n",
       "      <td>1f0566b71f7e</td>\n",
       "      <td>209.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703761</th>\n",
       "      <td>938774bbb675</td>\n",
       "      <td>280.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703762</th>\n",
       "      <td>53c046bac8cb</td>\n",
       "      <td>299.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703763</th>\n",
       "      <td>ead2377353d3</td>\n",
       "      <td>201.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703764</th>\n",
       "      <td>efa87c7d5160</td>\n",
       "      <td>176.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703765</th>\n",
       "      <td>f239d6ceb17b</td>\n",
       "      <td>218.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703766</th>\n",
       "      <td>0fef0826b1bc</td>\n",
       "      <td>219.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703767</th>\n",
       "      <td>478d3c34b0c1</td>\n",
       "      <td>221.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703768</th>\n",
       "      <td>6a1b6e3028fc</td>\n",
       "      <td>277.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703769</th>\n",
       "      <td>3b5fb022accd</td>\n",
       "      <td>349.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703770</th>\n",
       "      <td>a4456a9d271d</td>\n",
       "      <td>271.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703771</th>\n",
       "      <td>d43a25cf4ef2</td>\n",
       "      <td>252.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703772</th>\n",
       "      <td>8f47d2e020cd</td>\n",
       "      <td>252.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703773</th>\n",
       "      <td>a78af728d84b</td>\n",
       "      <td>210.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703774</th>\n",
       "      <td>d1ba45c7ec08</td>\n",
       "      <td>259.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703775</th>\n",
       "      <td>f69747f5ee68</td>\n",
       "      <td>284.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703776</th>\n",
       "      <td>2489963dc503</td>\n",
       "      <td>301.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703777</th>\n",
       "      <td>b0624c909f4c</td>\n",
       "      <td>307.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703778</th>\n",
       "      <td>24a1dfb06c10</td>\n",
       "      <td>256.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8703779</th>\n",
       "      <td>add681d54216</td>\n",
       "      <td>370.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8703780 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                   Id     Visits\n",
       "0        bf4edcf969af        7.0\n",
       "1        929ed2bf52b9        2.0\n",
       "2        ff29d0f51d5c        4.0\n",
       "3        e98873359be6        2.0\n",
       "4        fa012434263a        4.0\n",
       "5        48f1e93517a2        NaN\n",
       "6        5def418fcb36        5.0\n",
       "7        77bd08134351        1.0\n",
       "8        5889e6dbb16f        2.0\n",
       "9        5f21fef1d764        3.0\n",
       "10       6f07e1b8815a        5.0\n",
       "11       228e54b5dea0        1.0\n",
       "12       da1b34963ed7        2.0\n",
       "13       ab5ccefaa2db        1.0\n",
       "14       cbf42873ebf1        3.0\n",
       "15       ac67e35ed44e        1.0\n",
       "16       88c098aa640d   321959.0\n",
       "17       7c72842a89d1  1160760.0\n",
       "18       8ce002f2c329  1158477.0\n",
       "19       5f72d9920560  1138250.0\n",
       "20       f93afd7f5d9b    51572.0\n",
       "21       14011cb66f2d       20.0\n",
       "22       0065551ac465       15.0\n",
       "23       175f1872729e        8.0\n",
       "24       31d756e83124       10.0\n",
       "25       e186c2363c5e        9.0\n",
       "26       3bce56c2b977        7.0\n",
       "27       d497981dce77        5.0\n",
       "28       c813cec10548        4.0\n",
       "29       5123e0ed62c9        4.0\n",
       "...               ...        ...\n",
       "8703750  1fb8f902ad0f      376.0\n",
       "8703751  0107f6d7cd82      332.0\n",
       "8703752  30c402ed9e49      303.0\n",
       "8703753  935fa0168d01      321.0\n",
       "8703754  1140b428380e      342.0\n",
       "8703755  cc5eadae0d7a      349.0\n",
       "8703756  f923701cdb05      296.0\n",
       "8703757  905679a20d39      235.0\n",
       "8703758  642354a50690      279.0\n",
       "8703759  7376c63bd4c1      248.0\n",
       "8703760  1f0566b71f7e      209.0\n",
       "8703761  938774bbb675      280.0\n",
       "8703762  53c046bac8cb      299.0\n",
       "8703763  ead2377353d3      201.0\n",
       "8703764  efa87c7d5160      176.0\n",
       "8703765  f239d6ceb17b      218.0\n",
       "8703766  0fef0826b1bc      219.0\n",
       "8703767  478d3c34b0c1      221.0\n",
       "8703768  6a1b6e3028fc      277.0\n",
       "8703769  3b5fb022accd      349.0\n",
       "8703770  a4456a9d271d      271.0\n",
       "8703771  d43a25cf4ef2      252.0\n",
       "8703772  8f47d2e020cd      252.0\n",
       "8703773  a78af728d84b      210.0\n",
       "8703774  d1ba45c7ec08      259.0\n",
       "8703775  f69747f5ee68      284.0\n",
       "8703776  2489963dc503      301.0\n",
       "8703777  b0624c909f4c      307.0\n",
       "8703778  24a1dfb06c10      256.0\n",
       "8703779  add681d54216      370.0\n",
       "\n",
       "[8703780 rows x 2 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "correct_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# Check Id\n",
    "submit_id = submit_df['Id']\n",
    "correct_id = correct_df['Id']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(submit_id == correct_id).all()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "y_submit = submit_df['Visits'].values\n",
    "y_correct = correct_df['Visits'].values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([   2.617,    2.765,    2.771, ...,  252.518,  235.425,  231.818])"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_submit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([   7.,    2.,    4., ...,  307.,  256.,  370.])"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_correct"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((8703780,), (8703780,))"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_submit.shape, y_correct.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SMAPE Score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def smape(y_true, y_pred, axis=None):\n",
    "    '''Symmetric mean absolute percentage error'''\n",
    "    diff = np.abs((y_true - y_pred) / \n",
    "                  np.clip(np.abs(y_true) + np.abs(y_pred), 1e-7,\n",
    "                          None))\n",
    "    return 200. * np.nanmean(diff, axis=axis)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "44.633403134265613"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "smape(y_correct, y_submit)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
